﻿
@{
    ViewBag.Title = "Headportraits";
    Layout = "~/Views/Shared/_Layout.cshtml";
    var s = ViewBag.pic;
    var src = ViewBag.sic;
}
<script src="~/Scripts/jquery-1.10.2.min.js"></script>
上传钱
<img src="" id="touxiang" style="width:120px;height:100px;"/>
上传后
<img src="" id="touxiangs" style="width:120px;height:100px;" />

<input type="file" id="avatarInput"/>
<h2>Headportraits</h2>

@*<div><button onclick="update()">修改</button></div>
<div><button onclick="deletes()">删除</button></div>
<div><button onclick="add()">新增</button></div>
<div><button onclick="query()">查询</button></div>*@
<script>

    function add() {
        $.ajax({
            type: 'post',
            url: '/home/Headportraits',
            // url:'http://localhost:25352/api/usersserviceprovider/headportraits',
            data:{"type":"add"},
            async: false,
            cache: false,
            contentType: false,
            processData: false,
            success: function (data) {
                $('#touxiang').attr("src", data.is1);
                $('#touxiangs').attr("src", data.is2);
                alert(data);
            }
        });
    }
    function deletes() {
        $.ajax({
            type: 'post',
            url: '/home/Headportraits',
            // url:'http://localhost:25352/api/usersserviceprovider/headportraits',
            data: { "type": "delete" },
            async: false,
            cache: false,
            contentType: false,
            processData: false,
            success: function (data) {
                $('#touxiang').attr("src", data.is1);
                $('#touxiangs').attr("src", data.is2);
                alert(data);
            }
        });
    }
    function query() {

        $.ajax({
            type: 'post',
            url: '/home/Headportraits',
            // url:'http://localhost:25352/api/usersserviceprovider/headportraits',
            data: { "type": "query" },
            //async: false,
            //cache: false,
            //contentType: false,
            //processData: false,
            success: function (data) {
                $('#touxiang').attr("src", data.is1);
                $('#touxiangs').attr("src", data.is2);
                alert(data);
            }
        });
    }
    function update() {
        $.ajax({
            type: 'post',
            url: '/home/Headportraits',
            // url:'http://localhost:25352/api/usersserviceprovider/headportraits',
            data: { "type": "update" },
            //async: false,
            //cache: false,
            //contentType: false,
            //processData: false,
            success: function (data) {
                $('#touxiang').attr("src", data.is1);
                $('#touxiangs').attr("src", data.is2);
                alert(data);
            }
        });
    }
    var formdata;
    $("#avatarInput").change(function () {
        debugger
        var file = this.files[0];
        var formData = new FormData();
        formData.append('file', file);
        formData.append('name', "LPudding");
        formData.append('appid', "xtzt");
        $.ajax({
            type: 'post',
             url: '/home/Headportraits',
           // url:'http://localhost:25352/api/usersserviceprovider/headportraits',
             data: formData,
            async: false,
            cache: false,
            contentType: false,
            processData: false,
            success: function (data) {
                $('#touxiang').attr("src", data.is1);
                $('#touxiangs').attr("src", data.is2);
                //alert(data);
            }
        });
    })

    function ins(e) {
       
        $.ajax({
            type: 'post',
            url: '/home/Headportraits',
            data: formdata,
            async: false,
            cache: false,
            contentType: false,
            processData: false,
            success: function (data) {
                alert(data);
            }
        });
    }
   
</script>

